package com.fanfanwang.ffw.app.asynctask;

import java.util.LinkedHashMap;

import android.app.Activity;
import android.text.TextUtils;
import android.widget.Toast;

import com.fanfanwang.ffw.app.AppConstant;
import com.fanfanwang.ffw.app.R;
import com.fanfanwang.ffw.app.bean.SucGetOrdersListBean;
import com.fanfanwang.ffw.app.common.Md5Util;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.net.HttpRequest.HttpRequestException;
import com.fanfanwang.ffw.app.net.IssAsyncTask;
import com.fanfanwang.ffw.app.net.IssNetLib;
import com.fanfanwang.ffw.app.net.WebServiceHelper;
import com.fanfanwang.ffw.app.ui.service.ServiceYuYueListAct;

public class GetOrdersListAsyncTask extends
		IssAsyncTask<String, String, SucGetOrdersListBean> {
	private Activity mActivity;
	private String userid;
	private String page;
	private String pagesize;

	public GetOrdersListAsyncTask(Activity activity, String userid,
			String page, String pagesize) {
		super(activity);
		this.mActivity = activity;
		this.userid = userid;
		this.page = page;
		this.pagesize = pagesize;
	}

	@Override
	protected SucGetOrdersListBean doInBackground(String... params) {
		// TODO addAuctionPrice($apiusername,$apipassword,$userid,$pid,$price)
		SucGetOrdersListBean bean = null;
		LinkedHashMap<String, Object> paramsMap = new LinkedHashMap<String, Object>();
		paramsMap.put("apiusername", "parking");
		paramsMap.put("apipassword", Md5Util.getMD5To32("parking"));
		paramsMap.put("userid", userid);
		paramsMap.put("page", page);
		paramsMap.put("pagesize", pagesize);
		try {
			bean = IssNetLib.getInstance(mActivity).getOrdersList(
					WebServiceHelper._GETORDERSLIST, paramsMap);
			// TODO 自己填充数据
			/*
			 * bean=new SucGetOrdersListBean(); ArrayList<OrdersListBean>
			 * list=new ArrayList<OrdersListBean>(); OrdersListBean
			 * ordersListBean=new OrdersListBean(); ordersListBean.id="8";
			 * ordersListBean.parkingid="1"; ordersListBean.parkingname=
			 * "%E4%B8%87%E8%BE%BE%E5%81%9C%E8%BD%A6%E5%9C%BA";
			 * ordersListBean.parkingaddress=
			 * "%E6%B2%B3%E5%8C%97%E7%9F%B3%E5%AE%B6%E5%BA%84%E8%A3%95%E5%8D%8E%E5%8C%BA%E4%B8%87%E8%BE%BE%E5%B9%BF%E5%9C%BA"
			 * ; ordersListBean.addtime="1425021978"; OrdersListBean
			 * ordersListBean2=new OrdersListBean(); ordersListBean2.id="7";
			 * ordersListBean2.parkingid="1"; ordersListBean2.parkingname=
			 * "%E4%B8%87%E8%BE%BE%E5%81%9C%E8%BD%A6%E5%9C%BA";
			 * ordersListBean2.parkingaddress=
			 * "%E6%B2%B3%E5%8C%97%E7%9F%B3%E5%AE%B6%E5%BA%84%E8%A3%95%E5%8D%8E%E5%8C%BA%E4%B8%87%E8%BE%BE%E5%B9%BF%E5%9C%BA"
			 * ; ordersListBean2.addtime="1425021932"; OrdersListBean
			 * ordersListBean3=new OrdersListBean(); ordersListBean3.id="4";
			 * ordersListBean3.parkingid="1"; ordersListBean3.parkingname=
			 * "%E4%B8%87%E8%BE%BE%E5%81%9C%E8%BD%A6%E5%9C%BA";
			 * ordersListBean3.parkingaddress=
			 * "%E6%B2%B3%E5%8C%97%E7%9F%B3%E5%AE%B6%E5%BA%84%E8%A3%95%E5%8D%8E%E5%8C%BA%E4%B8%87%E8%BE%BE%E5%B9%BF%E5%9C%BA"
			 * ; ordersListBean3.addtime="1425019879"; list.add(ordersListBean);
			 * list.add(ordersListBean2); list.add(ordersListBean3);
			 * bean.status=1; bean.data=list;
			 */
		} catch (HttpRequestException e) {
			e.printStackTrace();
			// exception = getResources().getString(R.string.e_net_error);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			// exception = getResources().getString(R.string.e_json);
		}
		return bean;
	}

	@Override
	protected void onPostExecute(SucGetOrdersListBean result) {
		super.onPostExecute(result);
		ServiceYuYueListAct.mPullToRefreshListView.onRefreshComplete();
		if (exception != null) {
			ToastAlone.showToast(mActivity, exception);
			return;
		}
		if (result != null) {
			if (result.status == 1) {

				if (result.data != null) {
					ServiceYuYueListAct.iUpdateServiceYuYue
							.setServicYuYueList(result.data);
				}
			} else if (result.status == 0) {
				if (!TextUtils.isEmpty(result.msg)) {
					ToastAlone.showToast(mActivity,
							AppConstant.URLDecoderString(result.msg),
							Toast.LENGTH_SHORT).show();
				} else {
					ToastAlone.showToast(
							mActivity,
							mActivity.getResources().getString(
									R.string.e_net_error)).show();
				}
			}
		}
	}
}
